package com.songhq.data.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.songhq.data.bean.Sect;
import com.songhq.data.bean.PageVO;
import com.songhq.data.bean.Response;
import com.songhq.data.constant.ServiceCode;
import com.songhq.data.log.util.LogUtil;
import com.songhq.data.service.SectService;

@RestController
@RequestMapping("/sect")
public class SectController {
	
	
	@Autowired
	private  SectService sectService;
	

    /**
     * 列表
     * @param sect
     * @return
     */
    @GetMapping(value = "/list")
    public Response listSects( Sect sect) {
    	try {
    		LogUtil.info("SectController.listSects|sect = "+ JSON.toJSONString(sect));
    		PageVO result = sectService.listSects(sect);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "SectController.listSects");
            return Response.error(ServiceCode.FAIL, "查询列表异常");
        }
    }
    
    /**
     * 查看详情
     * @param sectId
     * @return
     */
    @GetMapping(value = "/getOne")
    public Response getOneSect( String sectId) {
    	try {
    		LogUtil.info("SectController.getOneSect|sectId = " + sectId);
    		Sect result = sectService.getOneSect(sectId);
            return Response.ok(result);
        } catch (Exception e) {
        	LogUtil.error(e, "SectController.getOneSect");
            return Response.error(ServiceCode.FAIL, "查询详情异常");
        }
    }
    
   
    @GetMapping(value = "/save")
    public Response saveSect( Sect sect) {
    	try {
    		LogUtil.info("SectController.saveSect|sect = " + JSON.toJSONString(sect));
    		sectService.saveSect(sect);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "SectController.saveSect");
            return Response.error(ServiceCode.FAIL, "新增异常");
        }
    }
    
    @GetMapping(value = "/update")
    public Response updateSect( Sect sect) {
    	try {
    		LogUtil.info("SectController.updateSect|sect = " + JSON.toJSONString(sect));
    		sectService.updateSect(sect);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "SectController.updateSect");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }
    @GetMapping(value = "/delete")
    public Response deleteSect( Sect sect) {
    	try {
    		LogUtil.info("SectController.updateSect|sect = " + JSON.toJSONString(sect));
    		sectService.deleteSect(sect);
            return Response.ok();
        } catch (Exception e) {
        	LogUtil.error(e, "SectController.updateSect");
            return Response.error(ServiceCode.FAIL, "修改异常");
        }
    }

}
